#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/9/2
# @Author  : YunZhen
# @File    : version.py
# @Software: PyCharm
"""
python版本管理模块
"""
from loguru import logger
from ._load import get_cached_versions, update_version_cache
from ._parse import get_all_python_versions_for_net


async def get_python_versions():
    """带缓存的版本获取"""
    # 尝试获取缓存
    versions = await get_cached_versions()
    if not versions:
        logger.debug("缓存无效或不存在，从官网获取最新版本信息")
        versions = await get_all_python_versions_for_net()
        # 更新缓存
        if versions:
            await update_version_cache(versions)
    # 重新组织数据结构
    all_systems_versions = {}
    for system, vers in versions.items():
        all_systems_versions[system] = set(vers.keys())
    return all_systems_versions
